﻿Imports System.Data.OleDb
Public Class addblogpost
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated Then
            If User.IsInRole("Gold") Then
                'Do Nothing
            Else
                Response.Redirect("opps.aspx?id=11")
            End If
        Else
            Response.Redirect("opps.aspx?id=10")
        End If
    End Sub

    Protected Sub btn_Blog_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Blog.Click
        Dim todaysDate As DateTime = New DateTime(Now.Year, Now.Month, Now.Day)
        Dim SQL As String = "INSERT INTO Blogs (Author,BlogTitle,BlogContent,CreatedDate) VALUES (@f1,@f2,@f3,@f4)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("CakeConnection").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(SQL, conn)
        cmd.Parameters.AddWithValue("@f1", Class1.getUserNumber(User.Identity.Name))
        cmd.Parameters.AddWithValue("@f2", tb_title.Text)
        cmd.Parameters.AddWithValue("@f3", tb_post.Text)
        cmd.Parameters.AddWithValue("@f4", todaysDate)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Dim redir As String
        redir = "Blogs.aspx?blogId=" & User.Identity.Name & "&uno=" & Class1.getUserNumber(User.Identity.Name)
        Response.Redirect(redir)
    End Sub
End Class